

package com.zmks.jkgj.xuexiao.controller;




import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Property;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.zmks.jkgj.core.controller.ABaseController;
import com.zmks.jkgj.core.resp.Resp;
import com.zmks.jkgj.xuexiao.SessionManager;
import com.zmks.jkgj.xuexiao.pojo.CrctConfigGrade;
import com.zmks.jkgj.xuexiao.pojo.CrctRelSchoolGrade;
import com.zmks.jkgj.xuexiao.resp.WebResp;
import com.zmks.jkgj.xuexiao.service.ICrctConfigGradeService;
import com.zmks.jkgj.xuexiao.service.ICrctObjGradeService;
import com.zmks.jkgj.xuexiao.service.ICrctRelSchoolGradeService;
import com.zmks.jkgj.xuexiao.vo.CrctConfigGradeVO;
import com.zmks.jkgj.xuexiao.vo.CrctConfigPositionVO;
import com.zmks.jkgj.xuexiao.vo.CrctObjGradeVO;
import com.zmks.jkgj.xuexiao.vo.CrctRelSchoolGradeVO;

@Controller
public class CrctRelSchoolGradeController extends ABaseController {
	

@Autowired
 private ICrctRelSchoolGradeService crctRelSchoolGradeService;
@Autowired
private ICrctConfigGradeService crctConfigGradeService;

//查询
@RequestMapping("/get_CrctRelSchoolGrade_list")
@ResponseBody
public Resp get_CrctRelSchoolGrade_list( Integer pageIndex,
		Integer pageSize,HttpServletRequest request) {
	WebResp 	webResp = new WebResp();
	try{
		if (pageIndex == null || pageSize == null) {
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("请检查网络！");
			
		}
		if (pageIndex == 1 || pageIndex == 0) {
			pageIndex = 1;
		}
	CrctRelSchoolGradeVO crctRelSchoolGradeVO=new  CrctRelSchoolGradeVO();
	String  school_oid = SessionManager.getsession(request).getSchool_oid();
	crctRelSchoolGradeVO.setSchool_oid(Long.parseLong(school_oid));
	
	List<CrctRelSchoolGradeVO> alist=crctRelSchoolGradeService.getList(crctRelSchoolGradeVO, (pageIndex - 1) * pageSize, pageSize);
	List data=new java.util.ArrayList();
	for(int i=0;i<alist.size();i++)
	{
		CrctRelSchoolGradeVO crctRelSchoolGradeVO2=alist.get(i);
	
		HashMap listmap=new HashMap();
		listmap.put("id",crctRelSchoolGradeVO2.getId() );
		String gradeName=crctConfigGradeService.get(crctRelSchoolGradeVO2.getGrade_oid()).getName();
		listmap.put("gradeName", gradeName );
		data.add(listmap);
	}
	
webResp.setData(data);
	webResp.setTotalCount(crctRelSchoolGradeService.getCount(crctRelSchoolGradeVO));
	  } catch (Exception e) {
			e.printStackTrace();
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("获取失败！");
			return webResp;
		}
		return webResp;

}

//查询
@RequestMapping("/get_CrctRelSchoolGrade_list_all")
@ResponseBody
public Resp get_CrctRelSchoolGrade_list(HttpServletRequest request) {
	WebResp 	webResp = new WebResp();
	try{
		
	CrctRelSchoolGradeVO crctRelSchoolGradeVO=new  CrctRelSchoolGradeVO();
	String  school_oid = SessionManager.getsession(request).getSchool_oid();
	crctRelSchoolGradeVO.setSchool_oid(Long.parseLong(school_oid));
	
	List<CrctRelSchoolGradeVO> alist=crctRelSchoolGradeService.getList(crctRelSchoolGradeVO);
	List data=new java.util.ArrayList();
	for(int i=0;i<alist.size();i++)
	{
		CrctRelSchoolGradeVO crctRelSchoolGradeVO2=alist.get(i);
	
		HashMap listmap=new HashMap();
		listmap.put("id",crctRelSchoolGradeVO2.getId() );
		String gradeName=crctConfigGradeService.get(crctRelSchoolGradeVO2.getGrade_oid()).getName();
		Long gradeid=crctConfigGradeService.get(crctRelSchoolGradeVO2.getGrade_oid()).getOid();
		listmap.put("gradeid", gradeid );
		listmap.put("gradeName", gradeName );
		data.add(listmap);
	}
	 webResp.setData(data);
	  } catch (Exception e) {
			e.printStackTrace();
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("获取失败！");
			return webResp;
		}
		return webResp;

}



//增加
@RequestMapping("/save_CrctRelSchoolGrade")
@ResponseBody
public Resp save_CrctConfigPosition(Long grade_oid ,HttpServletRequest request) {
	WebResp 	webResp = new WebResp();
	try{
		
		if(crctConfigGradeService.get(grade_oid)==null)
		{webResp.setRet(1);
		webResp.setErrcode(0);
		webResp.setMsg("请选择有效年纪！");
		return webResp;
			
		}
		
		CrctRelSchoolGradeVO crctRelSchoolGradeVO_seach=new  CrctRelSchoolGradeVO();
		crctRelSchoolGradeVO_seach.setGrade_oid(grade_oid);
		String  school_oid = SessionManager.getsession(request).getSchool_oid();
	
		crctRelSchoolGradeVO_seach.setSchool_oid(Long.parseLong(school_oid));
		List l=crctRelSchoolGradeService.getList(crctRelSchoolGradeVO_seach);
		if(l.size()>0)
		{
			
			webResp.setRet(1);
			webResp.setErrcode(0);
			webResp.setMsg("已经增加此项！");
			return webResp;
		}
		 
	CrctRelSchoolGradeVO crctRelSchoolGradeVO=new  CrctRelSchoolGradeVO();
	crctRelSchoolGradeVO.setGrade_oid(grade_oid);
	crctRelSchoolGradeVO.setCreate_date(new Date());
	
	crctRelSchoolGradeVO.setSchool_oid(Long.parseLong(school_oid));
	crctRelSchoolGradeService.save(crctRelSchoolGradeVO);
    } catch (Exception e) {
		e.printStackTrace();
		webResp.setRet(1);
		webResp.setErrcode(0);
		webResp.setMsg("增加失败！");
		return webResp;
	}
	return webResp;
}
//删除
@RequestMapping("/remove_CrctRelSchoolGrade")
@ResponseBody
public Resp remove_CrctObjGrade(Long id,HttpServletRequest request) {
	WebResp 	webResp = new WebResp();
	CrctObjGradeVO CrctObjGradeVO=new  CrctObjGradeVO();
	//判断是否关联
	
	crctRelSchoolGradeService.remove(id);
	return webResp;
}



}
